
# Generate report in HTML
class Report
  attr_reader :directory, :title, :filename
  
  
  
  
  # Specisify the output directory and the report title
  def initialize(directory, title)
    @sections = []
    @directory = directory
    @title = title
    @filename = title.gsub(/\s/,'').downcase + ".html"        
  end
  
  def new_section(title, text=nil, chart=nil, chart_name=nil)
    @sections << Section.new(self, title, text, chart, chart_name)
  end
  
  #output to html
  def to_html
    Dir.mkdir(@directory) unless File.directory?(@directory)
    File.open(@directory +"/" + @filename, 'w') do |f| 
      f.puts("<html><title>#{title}</title><body>")
      f.puts("<h1>#{title}</h1>")
      @sections.each { |s| f.puts(s.to_html)}
      f.puts("</body></html>")
    end
  end
  
end